package com.tanhua.server.controller;

import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author feihao
 * @version 1.0
 * @date 2021/6/29 20:12
 */

//交友：
@Slf4j
@RestController
@RequestMapping("tanhua")
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;


    //今日佳人接口
    @GetMapping("todayBest")
    public ResponseEntity<TodayBest> findTodayBest() {

        try {
            TodayBest todayBest = todayBestService.findTodayBest();
            if (todayBest != null) {
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人出错！userId=" + UserThreadLocal.get().getId(), e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    //推荐人接口：
    @GetMapping("recommendation")
    public ResponseEntity<PageResult> findRecommendation( RecommendUserQueryParam param) {

        //调用  todayBestService进行查询:
        try {
            PageResult pageResult = todayBestService.findRecommendation(param);
            if (pageResult != null) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐人列表出错！ userId=" + UserThreadLocal.get(), e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
